package com.hucheng.order.vo;

import com.hucheng.order.entity.OrderInfoDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回界面数据
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderInfoVO implements Serializable {
    private Integer orderId;
    private String orderNumber;
    private String tradeNo;
    private Integer userId;
    private Integer status;
    private BigDecimal orderAmount;
    private BigDecimal payAmount;
    private BigDecimal totalAmount;
    private String datePay;
    private Integer addressId;
    private String remark;
    private Integer isDel;
    private String dateCreated;
    private String dateUpdated;

    public static OrderInfoVO buildOrderInfoVO(final OrderInfoDO orderDO) {
        if (orderDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return new OrderInfoVO(orderDO.getOrderId(),
                orderDO.getOrderNumber(),
                orderDO.getTradeNo(),
                orderDO.getUserId(),
                orderDO.getStatus(),
                orderDO.getOrderAmount(),
                orderDO.getPayAmount(),
                orderDO.getTotalAmount(),
                orderDO.getDatePay() == null ? null : sdf.format(orderDO.getDatePay()),
                orderDO.getAddressId(),
                orderDO.getRemark(),
                orderDO.getIsDel(),
                orderDO.getDateCreated() == null ? null : dateTimeFormatter.format(orderDO.getDateCreated().toLocalDateTime()),
                orderDO.getDateUpdated() == null ? null : dateTimeFormatter.format(orderDO.getDateUpdated().toLocalDateTime()));
    }
}
